package com.yonyou.iuap.controller.pc;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yonyou.iuap.pub.JsonUtils;
import com.yonyou.iuap.shell.pub.ResultDto;
import com.yonyou.iuap.shell.service.intf.ICompatibleService;

/**
 * 竟品
 * **/
@Controller
@RequestMapping("/pcBdCompatible")
public class PCBdCompatibleController {
	private final Logger logger = (Logger) LoggerFactory.getLogger(getClass());
	private long start,end;
	@Autowired
	private ICompatibleService iCompatibleService;

	/**
	 * 竟品查所有
	 * **/
	@RequestMapping(value = "/queryAll", method = RequestMethod.POST)
	public @ResponseBody String LikeIKnowledgeCategory(@RequestBody Map map,HttpServletRequest request,HttpServletResponse response) {
		start=System.currentTimeMillis();
		ResultDto rsdto = new ResultDto();

		rsdto = iCompatibleService.selectAll();
		String rs_json = JsonUtils.toJsonStr(rsdto);
		end=System.currentTimeMillis();
		logger.info("queryAll接口调用时间"+String.valueOf(end-start));
		return rs_json;
	}
	
	/**
	 * 竞品查询
	 * {"type":"3","pk_product":"1","name":"油品"}
	 * **/
	@RequestMapping(value = "/queryCompatible", method = RequestMethod.POST)
	public @ResponseBody String queryCompatible(@RequestBody Map param,HttpServletRequest request,HttpServletResponse response){
		start=System.currentTimeMillis();
		ResultDto rsdto = new ResultDto();
		//1查询所有，2根据关键字查询，3模糊查询
		String type=param.get("type")==null?"":param.get("type").toString();
		if("1".equals(type)){
			param.put("pageNum",(Integer.valueOf(param.get("pageNum").toString())-1)*Integer.valueOf(param.get("pageSize").toString()));
			param.put("pageSize",Integer.valueOf(param.get("pageSize").toString()));
			rsdto = iCompatibleService.selectAllPage(param);
		}else if("2".equals(type)){
			rsdto = iCompatibleService.queryCompatible(param);
		}else if("3".equals(type)){
			rsdto = iCompatibleService.selectByConditionPage(param);
		}
		
		String rs_json = JsonUtils.toJsonStr(rsdto);
		end=System.currentTimeMillis();
		logger.info("queryCompatible接口调用时间"+String.valueOf(end-start));
		return rs_json;
	}
}
